//Produces a Mass file.  This is a large batch file thatis designed to
//perform massive runs of the CSP.  It requires two inputs: a .mass file
//which tells the program what makefiles
//and outputs should be used, and a batch file which tells the subprogram
// makeRun.out what combinations of parameters are needed.

#include <iostream>
#include <fstream>
#include <cstdlib>
#include <cstdio>
#include <string>
using namespace std;

int main(int argc,char *argv[])
{
	if(argc!=3)
	{
		cout << "Mass Config File, Batch Config File" << endl;
		exit(1);
	}

	ifstream open(argv[2]);
	if(!open)
	{
		cout << "FAILURE: bad batch file" << endl;
		exit(1);
	}
	ifstream batch(argv[1]);
	if(!batch)
	{
		cout << "FAILURE: bad mass file" << endl;
		exit(1);
	}
	string heur_base;
	string ac_suffix;
	string output_base;
	
	ofstream mass("Mass");
	int AC_types;
	batch >> AC_types;
	for(int ac=0;ac<AC_types;ac++)
	{
		batch >> ac_suffix;
		int maketypes;
		batch >> maketypes;
		for(int i=0;i<maketypes;i++)
		{
			batch >> heur_base;
			batch >> output_base;
			mass << "make -B -j4 -f " << heur_base << ac_suffix << ".make" << endl;
			mass << "makeRun.out " << argv[2] << " " << output_base << ac_suffix << " runx" << endl;
			mass << "runx" << endl;

		}
	}
	mass.close();
	system("chmod +x Mass");
}

